﻿using System;
using System.Globalization;

namespace WGS84
{
    public class Radians
    {
        Double _radians;

        /// <summary>
        /// Instance Constructor
        /// </summary>
        /// <param name="radians">Angle in radians</param>
        public Radians(double radians)
        {
            _radians = radians;
        }

        /// <summary>
        /// Angle in radians
        /// </summary>
        /// <returns>Double precision value</returns>
        public double ToDouble()
        {
            return _radians;
        }

        /// <summary>
        /// Angle converted to degrees
        /// </summary>
        /// <returns>Double precision value</returns>
        public double ToDegrees()
        {
            return _radians * (180.0 / Math.PI);
        }

        /// <summary>
        /// Compares by value two Radians objects
        /// </summary>
        /// <param name="obj">object for comparison</param>
        /// <returns>Whether they are equal</returns>
        public override bool Equals(object obj)
        {
            if (obj == null) return false;

            if (ReferenceEquals(this, obj)) return true;

            if (GetType() != obj.GetType()) return false;
            Radians that = (Radians)obj;

            if (!_radians.Equals(that._radians)) return false;

            return true;
        }

        /// <summary>
        /// Calculate Hash code for this object
        /// </summary>
        /// <returns>Hashcode based on member variables</returns>
        public override int GetHashCode()
        {
            int hash = _radians.GetHashCode();
            return hash;
        }

        /// <summary>
        /// Get legible string
        /// </summary>
        /// <returns>Human readable string</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{0} Radians", _radians);
        }
    }
}
